package com.example.gif.controller;

import com.example.gif.service.GenerateGifService;
import com.example.gif.vo.ImageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:YangHaoZhong
 * @time:2024/4/8
 */
@RestController
@RequestMapping({"/generate"})
public class GenerateGifController {

    @Autowired
    private GenerateGifService generateGifImageService;

    @PostMapping({"/gif"})
    public ResponseEntity getMetrics(ImageInfo imageInfo) throws Exception {
        ByteArrayResource image = this.generateGifImageService.getImage(imageInfo);
        return ResponseEntity.ok().contentType(MediaType.valueOf("image/gif")).body(image);
    }
}
